using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using Spacejock;
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows.Forms;
using yW5Lib;
using yWriter6.My.Resources;

namespace yWriter6
{
	[DesignerGenerated]
	public class frmWordLog : Form
	{
		private IContainer components;

		[CompilerGenerated]
		[AccessedThroughProperty("ListView1")]
		private ListView _ListView1;

		[CompilerGenerated]
		[AccessedThroughProperty("ColumnHeader1")]
		private ColumnHeader _ColumnHeader1;

		[CompilerGenerated]
		[AccessedThroughProperty("ColumnHeader2")]
		private ColumnHeader _ColumnHeader2;

		[CompilerGenerated]
		[AccessedThroughProperty("ColumnHeader3")]
		private ColumnHeader _ColumnHeader3;

		[CompilerGenerated]
		[AccessedThroughProperty("ColumnHeader4")]
		private ColumnHeader _ColumnHeader4;

		[CompilerGenerated]
		[AccessedThroughProperty("ColumnHeader5")]
		private ColumnHeader _ColumnHeader5;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdOK")]
		private Button _cmdOK;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdResetToday")]
		private Button _cmdResetToday;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdClip")]
		private Button _cmdClip;

		private clsProject cProjectLocal;

		[field: AccessedThroughProperty("ListView1")]
		internal virtual ListView ListView1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("ColumnHeader1")]
		internal virtual ColumnHeader ColumnHeader1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("ColumnHeader2")]
		internal virtual ColumnHeader ColumnHeader2
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("ColumnHeader3")]
		internal virtual ColumnHeader ColumnHeader3
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("ColumnHeader4")]
		internal virtual ColumnHeader ColumnHeader4
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("ColumnHeader5")]
		internal virtual ColumnHeader ColumnHeader5
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		internal virtual Button cmdOK
		{
			[CompilerGenerated]
			get
			{
				return _cmdOK;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdOK_Click;
				Button cmdOK = _cmdOK;
				if (cmdOK != null)
				{
					cmdOK.Click -= value2;
				}
				_cmdOK = value;
				cmdOK = _cmdOK;
				if (cmdOK != null)
				{
					cmdOK.Click += value2;
				}
			}
		}

		internal virtual Button cmdResetToday
		{
			[CompilerGenerated]
			get
			{
				return _cmdResetToday;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdResetToday_Click;
				Button cmdResetToday = _cmdResetToday;
				if (cmdResetToday != null)
				{
					cmdResetToday.Click -= value2;
				}
				_cmdResetToday = value;
				cmdResetToday = _cmdResetToday;
				if (cmdResetToday != null)
				{
					cmdResetToday.Click += value2;
				}
			}
		}

		internal virtual Button cmdClip
		{
			[CompilerGenerated]
			get
			{
				return _cmdClip;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdClip_Click;
				Button cmdClip = _cmdClip;
				if (cmdClip != null)
				{
					cmdClip.Click -= value2;
				}
				_cmdClip = value;
				cmdClip = _cmdClip;
				if (cmdClip != null)
				{
					cmdClip.Click += value2;
				}
			}
		}

		public frmWordLog()
		{
			base.FormClosing += frmWordLog_FormClosing;
			base.Load += frmWordLog_Load;
			InitializeComponent();
		}

		[DebuggerNonUserCode]
		protected override void Dispose(bool disposing)
		{
			try
			{
				if (disposing && components != null)
				{
					components.Dispose();
				}
			}
			finally
			{
				base.Dispose(disposing);
			}
		}

		[System.Diagnostics.DebuggerStepThrough]
		private void InitializeComponent()
		{
			ListView1 = new System.Windows.Forms.ListView();
			ColumnHeader1 = new System.Windows.Forms.ColumnHeader();
			ColumnHeader2 = new System.Windows.Forms.ColumnHeader();
			ColumnHeader3 = new System.Windows.Forms.ColumnHeader();
			ColumnHeader4 = new System.Windows.Forms.ColumnHeader();
			ColumnHeader5 = new System.Windows.Forms.ColumnHeader();
			cmdOK = new System.Windows.Forms.Button();
			cmdResetToday = new System.Windows.Forms.Button();
			cmdClip = new System.Windows.Forms.Button();
			SuspendLayout();
			ListView1.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right);
			ListView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[5]
			{
				ColumnHeader1,
				ColumnHeader2,
				ColumnHeader3,
				ColumnHeader4,
				ColumnHeader5
			});
			ListView1.Location = new System.Drawing.Point(10, 13);
			ListView1.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			ListView1.Name = "ListView1";
			ListView1.Size = new System.Drawing.Size(531, 437);
			ListView1.Sorting = System.Windows.Forms.SortOrder.Descending;
			ListView1.TabIndex = 0;
			ListView1.UseCompatibleStateImageBehavior = false;
			ListView1.View = System.Windows.Forms.View.Details;
			ColumnHeader1.Text = "Date";
			ColumnHeader1.Width = 87;
			ColumnHeader2.Text = "Progressive";
			ColumnHeader2.Width = 106;
			ColumnHeader3.Text = "Daily";
			ColumnHeader3.Width = 89;
			ColumnHeader4.Text = "With Unused";
			ColumnHeader4.Width = 129;
			ColumnHeader5.Text = "Daily";
			ColumnHeader5.Width = 119;
			cmdOK.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			cmdOK.Location = new System.Drawing.Point(451, 456);
			cmdOK.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			cmdOK.Name = "cmdOK";
			cmdOK.Size = new System.Drawing.Size(89, 41);
			cmdOK.TabIndex = 1;
			cmdOK.Text = "Close";
			cmdOK.UseVisualStyleBackColor = true;
			cmdResetToday.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			cmdResetToday.Location = new System.Drawing.Point(226, 456);
			cmdResetToday.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			cmdResetToday.Name = "cmdResetToday";
			cmdResetToday.Size = new System.Drawing.Size(150, 41);
			cmdResetToday.TabIndex = 1;
			cmdResetToday.Text = "Reset Today's Count";
			cmdResetToday.UseVisualStyleBackColor = true;
			cmdClip.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			cmdClip.Location = new System.Drawing.Point(10, 456);
			cmdClip.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			cmdClip.Name = "cmdClip";
			cmdClip.Size = new System.Drawing.Size(150, 41);
			cmdClip.TabIndex = 1;
			cmdClip.Text = "Copy to clipboard";
			cmdClip.UseVisualStyleBackColor = true;
			base.AutoScaleDimensions = new System.Drawing.SizeF(7f, 17f);
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			base.ClientSize = new System.Drawing.Size(551, 509);
			base.Controls.Add(cmdClip);
			base.Controls.Add(cmdResetToday);
			base.Controls.Add(cmdOK);
			base.Controls.Add(ListView1);
			Font = new System.Drawing.Font("Segoe UI", 10f);
			base.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			base.Name = "frmWordLog";
			Text = "Daily Progress";
			ResumeLayout(false);
		}

		private void cmdOK_Click(object sender, EventArgs e)
		{
			Hide();
		}

		public void DataToForm(ref clsProject cProject)
		{
			cProjectLocal = cProject;
			FillList();
		}

		private void FillList()
		{
			int num = 0;
			int num2 = 0;
			ListView1.SuspendLayout();
			ListView1.Items.Clear();
			try
			{
				IEnumerator enumerator = default(IEnumerator);
				try
				{
					enumerator = cProjectLocal.WordLogs.GetEnumerator();
					while (enumerator.MoveNext())
					{
						clsWordLog clsWordLog = (clsWordLog)enumerator.Current;
						ListViewItem listViewItem = ListView1.Items.Add(Strings.Format(clsWordLog.LogDate, "yyyy-MM-dd"));
						listViewItem.SubItems.Add(Conversions.ToString(clsWordLog.WordCount));
						listViewItem.SubItems.Add(Conversions.ToString(clsWordLog.WordCount - num));
						listViewItem.SubItems.Add(Conversions.ToString(clsWordLog.TotalWordCount));
						listViewItem.SubItems.Add(Conversions.ToString(clsWordLog.TotalWordCount - num2));
						num = clsWordLog.WordCount;
						num2 = clsWordLog.TotalWordCount;
					}
				}
				finally
				{
					if (enumerator is IDisposable)
					{
						(enumerator as IDisposable).Dispose();
					}
				}
			}
			catch (Exception ex)
			{
				ProjectData.SetProjectError(ex);
				Exception ex2 = ex;
				clsShared.cLog.AddAction(ex2, MethodBase.GetCurrentMethod());
				ProjectData.ClearProjectError();
			}
			ListView1.ResumeLayout();
		}

		private void frmWordLog_FormClosing(object sender, FormClosingEventArgs e)
		{
			clsShared.cSettings.StoreWindowSettings("WordLog", this);
			clsSettings cSettings = clsShared.cSettings;
			ListView List = ListView1;
			cSettings.StoreColumnSettings("WordLog", ref List);
			ListView1 = List;
		}

		private void frmWordLog_Load(object sender, EventArgs e)
		{
			base.Icon = Resources.yWriter5_Ico;
			clsSettings cSettings = clsShared.cSettings;
			Form Form = this;
			cSettings.ReadWindowSettings("WordLog", ref Form);
			clsSettings cSettings2 = clsShared.cSettings;
			ListView List = ListView1;
			cSettings2.ReadColumnSettings("WordLog", ref List);
			ListView1 = List;
		}

		private void cmdResetToday_Click(object sender, EventArgs e)
		{
			try
			{
				if (Interaction.MsgBox("This will move today's wordcount onto yesterday's (no undo!) Are you sure?", MsgBoxStyle.YesNo) == MsgBoxResult.Yes)
				{
					DateTime countDate = DateAndTime.Now.Date.Subtract(new TimeSpan(1, 0, 0, 0));
					cProjectLocal.WordLogs.UpdateCount(cProjectLocal.Wordcount(), cProjectLocal.WordcountWithUnused(), countDate);
					cProjectLocal.WordLogs.UpdateCount(cProjectLocal.Wordcount(), cProjectLocal.WordcountWithUnused(), DateAndTime.Now.Date);
					FillList();
				}
			}
			catch (Exception ex)
			{
				ProjectData.SetProjectError(ex);
				Exception ex2 = ex;
				clsShared.cLog.AddAction(ex2, MethodBase.GetCurrentMethod());
				ProjectData.ClearProjectError();
			}
		}

		private void cmdClip_Click(object sender, EventArgs e)
		{
			StringBuilder stringBuilder = new StringBuilder();
			int num = 0;
			int num2 = 0;
			stringBuilder.AppendLine("Date\tProgressive\tCount\tWith Unused\tWith Unused");
			IEnumerator enumerator = default(IEnumerator);
			try
			{
				enumerator = cProjectLocal.WordLogs.GetEnumerator();
				while (enumerator.MoveNext())
				{
					clsWordLog clsWordLog = (clsWordLog)enumerator.Current;
					stringBuilder.Append(Strings.Format(clsWordLog.LogDate, "yyyy-MM-dd") + "\t");
					stringBuilder.Append(Conversions.ToString(clsWordLog.WordCount) + "\t");
					stringBuilder.Append(Conversions.ToString(clsWordLog.WordCount - num) + "\t");
					stringBuilder.Append(Conversions.ToString(clsWordLog.TotalWordCount) + "\t");
					stringBuilder.Append(Conversions.ToString(clsWordLog.TotalWordCount - num2));
					stringBuilder.AppendLine();
					num = clsWordLog.WordCount;
					num2 = clsWordLog.TotalWordCount;
				}
			}
			finally
			{
				if (enumerator is IDisposable)
				{
					(enumerator as IDisposable).Dispose();
				}
			}
			Clipboard.Clear();
			Clipboard.SetText(stringBuilder.ToString(), TextDataFormat.Text);
		}
	}
}
